import java.security.MessageDigest;

public class Foo {
    public final static String generateMd5(String string) {
        try {
            char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
            byte[] inputBytes = string.getBytes("UTF-8");
            MessageDigest mdInst = MessageDigest.getInstance("md5");            // 使用指定的字节更新摘要
            mdInst.update(inputBytes);            // 获得密文
            byte[] md = mdInst.digest();            // 把密文转换成十六进制的字符串形式
            int j = md.length;
            char str[] = new char[j * 2];
            int k = 0;
            for (int i = 0; i < j; i++) {
                byte byte0 = md[i];                // 将每个数(int)b进行双字节加密
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            //LOG.info("签名md5结果：" + str);
            return new String(str);
        } catch (Exception e) {
            // LOG.error("md5加密异常" + e.getMessage());
        }
        return null;
    }

}
